import requests

import config
from api.ihrm_manage_api import TestManage
from common.db_util import DBUtil
from common.ihrm_ass import IhrmAssert
from common.token_ihrm import  TokenIhrm


class TestIhrm2:
    def setup_class(self):
        self.token = TokenIhrm.token_login()

    def setup(self):
        del_sql = f"delete from bs_user where mobile = '{config.TEL}';"
        DBUtil.uid_db(del_sql)

    def teardown(self):
        del_sql = f"delete from bs_user where mobile = '{config.TEL}';"
        DBUtil.uid_db(del_sql)

    def test_login(self):
        add_emp_boby = {
            "username": "小猪佩奇",
            "mobile": "15912345678",
            "workNumber": "22"
        }
        resp = TestManage.add_emp_api(self.token, add_emp_boby)
        print(resp.json())
        IhrmAssert.login_assert(resp, 200, True, 10000, "操作成功！")

    def test1_login(self):
        add_emp_boby = {"username": "xiaoming_02", "mobile": "15912347678", "timeOfEntry": "2022-04-01",
                        "formOfEmployment": 1, "workNumber": "137", "departmentName": "人事部门",
                        "departmentId": "1514178739884359680", "correctionTime": "2022-04-29T16:00:00.000Z"}
        resp = TestManage.add_emp_api(self.token, add_emp_boby)
        print(resp.json())
        IhrmAssert.login_assert(resp, 200, True, 10000, "操作成功！")

    def test2_login(self):
        add_emp_boby = {"mobile": "15912345678", "username": "xiaoming_001", "workNumber": "123"}
        resp = TestManage.add_emp_api(self.token, add_emp_boby)
        print(resp.json())
        IhrmAssert.login_assert(resp, 200, True, 10000, "操作成功！")

    # def test_query(self):
    #     emp_id = "1552914940887576576"
    #     resp = TestManage.add_emp_api(self.token, emp_id)
    #     print(resp.json())
    #     IhrmAssert.login_assert(resp, 200, False, 99999, "抱歉，系统繁忙，请稍后重试！")

    # def test_modify(self):
    #     modify_url = " http://ihrm2-test.itheima.net/api/sys/user/员工id"
    #     modify_emp_header = {"Content-Type": "application/json",
    #                          "Authorization": "Bearer 9f79fe2c-0e05-430b-9570-e7ad19167f82"}
    #     modify_boby = {"username": "齐天大圣"}
    #     resp_modify = requests.put(url=modify_url, headers=modify_emp_header, json=modify_boby)
    #     return resp_modify
    #
    # def test_delete(self):
    #     delete_emp_url = "http://ihrm2-test.itheima.net/api/sys/user/员工id"
    #     delete_head = {"Authorization": "Bearer 9f79fe2c-0e05-430b-9570-e7ad19167f82"}
    #     resp_delete = requests.delete(url=delete_emp_url, headers=delete_head)
    #     return resp_delete
